<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: ThemeManCss.php 323 2008-12-01 18:32:53Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Common.Data.PortalThemeRecord');
Prado::using('Application.Common.Data.PortalThemeCssClassRecord');
Prado::using('Application.Common.Data.PortalThemeCssClassAttrRecord');

class ThemeManCss extends PortalAdminPage
{
	private $_themeid;

	public function setThemeId($value)
	{
		$this->_themeid	= $value;
	}

	public function getThemeId()
	{
		return $this->_themeid;
	}

	public function onInit($param)
	{
		parent::onInit($param);
		$this->ThemeId	= TPropertyValue::ensureInteger($this->Request['id']);
	}

	public function getDataRows($offset, $rows)
	{
		return $this->DataAccess->createCommand("select * from tblthemecssclasses where themeid=" . $this->ThemeId . " order by name LIMIT $offset,$rows")->query();
	}

	protected function getRowCount()
    {
        return $this->DataAccess->createCommand("select count(id) from tblthemecssclasses where themeid=" . $this->ThemeId)->queryScalar();
    }

	public function onLoad($param)
	{
		parent::onLoad($param);

		if(!$this->IsPostBack)
		{
			$this->ThemeListCss->VirtualItemCount	= $this->RowCount;
			$this->ThemeListCss->DataSource			= $this->getDataRows(0,$this->ThemeListCss->PageSize);
			$this->ThemeListCss->dataBind();
		}
	}

	public function pageChanged($sender,$param)
    {
        $this->ThemeListCss->CurrentPageIndex	= $param->NewPageIndex;
		$this->ThemeListCss->DataSource			= $this->getDataRows($this->ThemeListCss->CurrentPageIndex * $this->ThemeListCss->PageSize,$this->ThemeListCss->PageSize);
		$this->ThemeListCss->dataBind();
    }

	public function itemCommand($s,$p)
	{
	}

	public function deleteItem($sender, $param)
	{
		$id = $this->ThemeListCss->DataKeys[$param->Item->ItemIndex];
		$classRec	= PortalThemeCssClassRecord::finder()->findByid($id);

		if($classRec !== null)
		{
			$classRec->delete();
		}

		$this->ThemeListCss->VirtualItemCount	= $this->RowCount;
		$this->ThemeListCss->DataSource			= $this->getDataRows(0,$this->ThemeListCss->PageSize);
		$this->ThemeListCss->dataBind();
	}
}
?>